home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13910 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: A weird thing about printf()
  5. Date: 10 Apr 1996 21:10:09 GMT
  6. Organization: OpenVision
  7. Message-ID: <4kh83h$fml@spanky.pls.ov.com>
  8. References: <4kflr2$5if@dewey.csun.edu>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 5if@dewey.csun.edu, kc44097@csun.edu (chen) writes:
  13. >
  14. >  
  15. >  The program :
  16. >
  17. >#include <stdio.h>
  18. >
  19. >int answer;
  20. >main()
  21. >{
  22. >  answer=2+2;
  23. >  printf("The answer is %d\n");
  24. >  return 0;
  25. >}
  26. >
  27. >  In printf(),I lost "answer" in the end,but it works,and give me the
  28. >result 0.I wonder how the compiler handle this condition.Also,is this
  29. >allow by C?(by this, I mean is this a leagal usage in language itself,
  30. >or just a mistake cause by the compiler?)
  31. >
  32. >  Can someone give me some advice ? Please e-mail me :
  33. >                   kc44097@huey.csun.edu
  34. >
  35. >                 Thankx !!!!!!
  36.  
  37.  
  38. You are lucky that you did not get a segment violation or other error.
  39. The "%d" tells printf that there is an argument.  In not supplying the
  40. argument, you accept whatever the system does to read a non-existent
  41. argument.  The compiler is (usually) incapable of checking for the
  42. correct number of arguments in a variable argument function (such
  43. as printf).
  44.  
  45.             Fletcher.Glenn@ov.com
  46.  
  47.  
  48.